package com.neuedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.neuedu.pojo.Result;
import com.neuedu.pojo.TAccount;
import com.neuedu.mapper.TAccountMapper;
import com.neuedu.service.ITAccountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhangsan
 * @since 2024-06-17
 */
@Service
public class TAccountServiceImpl extends ServiceImpl<TAccountMapper, TAccount> implements ITAccountService {
    @Autowired
    TAccountMapper tAccountMapper;

    @Override
    public List<TAccount> login(String accUsername, String accPassword) {
        TAccount tAccount = new TAccount();
        tAccount.setAccUsername(accUsername);
        tAccount.setAccPassword(accPassword);
        LambdaQueryWrapper<TAccount> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TAccount::getAccUsername, accUsername)
                .eq(TAccount::getAccPassword, accPassword);
        List<TAccount> tAccounts = tAccountMapper.selectList(wrapper);
        return tAccounts;
    }

    @Override
    public int add(TAccount account) {
        return tAccountMapper.insert(account);
    }

    @Override
    public Result changeacc(TAccount account) {
        account.setUpdateTime(LocalDateTime.now());
        return Result.success(tAccountMapper.updateById(account),"修改成功");
    }
}
